package com.ksd.modules.special.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.special.po.AdminSpecialBindUserBuySavePO;
import com.ksd.modules.special.po.AdminSpecialBindUserBuySearchPO;
import com.ksd.modules.special.service.IAdminSpecialBindUserBuyService;
import com.ksd.modules.special.vo.AdminSpecialBindUserBuyVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminSpecialBindUserBuyController extends BaseController {

    @Autowired
    private IAdminSpecialBindUserBuyService adminSpecialBindUserBuyService;

    /**
     * 【专题分类】-【订单】- 列表
     * @return
     */
    @PostMapping("/special/bind/order/list")
    public R<Page<AdminSpecialBindUserBuyVo>> findAdminSpecialBinds(@Validated @RequestBody AdminSpecialBindUserBuySearchPO adminSpecialCategorySearchPO){
        return R.data(adminSpecialBindUserBuyService.findAdminSpecialBindUserBuys(adminSpecialCategorySearchPO));
    }


    /**
     * 【专题分类】-【订单】- 保存和更新
     * @param adminSpecialCategorySavePO
     * @return
     */
    @PostMapping("/special/bind/order/saveupdate")
    @ApiLog("【专题分类】-【订单】- 保存和更新")
    @RepeatSubmit
    public R<AdminSpecialBindUserBuyVo> saveUpdateAdminSpecialBind(@Validated @RequestBody AdminSpecialBindUserBuySavePO adminSpecialCategorySavePO){
        return R.data(adminSpecialBindUserBuyService.saveUpdateAdminSpecialBindUserBuy(adminSpecialCategorySavePO));
    }

    /**
     * 【专题分类】-【订单】- 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/special/bind/order/get/{id}")
    public R<AdminSpecialBindUserBuyVo> getAdminSpecialBindById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindUserBuyService.getAdminSpecialBindUserBuyById(id));
    }

    /**
     * 【专题分类】-【订单】- 批量彻底删除
     *
     * @return
     */
    @PostMapping("/special/bind/order/batch/remove")
    @ApiLog("【专题分类】-【订单】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminSpecialBind(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminSpecialBindUserBuyService.batchRemovesAdminSpecialBindUserBuy(batchIdsPO));
    }

    /**
     * 【专题分类】-【订单】- 单个物理删除
     * @param id
     * @return
     */
    @PostMapping("/special/bind/order/remove/{id}")
    @ApiLog("【专题分类】-【订单】- 单个物理删除")
    public R<Boolean> removeAdminSpecialBindById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindUserBuyService.removeAdminSpecialBindUserBuyById(id));
    }

    /**
     * 【专题分类】-【订单】- 修改状态
     *
     * @return
     */
    @PostMapping("/special/bind/order/status/{id}/{field}")
    @ApiLog("【专题分类】-【订单】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminSpecialBindUserBuyService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminSpecialBindUserBuyService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【专题分类】-【订单】- 绑定订单
     *
     * @return
     */
    @PostMapping("/special/bind/order/userbind")
    @ApiLog("【专题分类】-【订单】- 绑定订单")
    @RepeatSubmit
    public R<Boolean> bindUserOrder(
            @RequestParam("uuid")String uuid,
            @RequestParam("opid") Long opid
    ) {
        return R.data(adminSpecialBindUserBuyService.bindUserOrder(uuid, opid));
    }
}
